home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / mapdups.py < prev    next >
Text File  |  2004-01-05  |  10KB  |  346 lines

  1. """   QuArK  -  Quake Army Knife
  2.  
  3. Python code to implement the various Duplicator styles.
  4. """
  5. #
  6. # Copyright (C) 1996-99 Armin Rigo
  7. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  8. # FOUND IN FILE "COPYING.TXT"
  9. #
  10.  
  11. #$Header: /cvsroot/quark/runtime/plugins/mapdups.py,v 1.12 2003/03/24 08:57:15 cdunde Exp $
  12.  
  13.  
  14. #
  15. # Feel free to add your own styles here, or better
  16. # in a new plug-in that looks like this one.
  17. #
  18.  
  19. Info = {
  20.    "plug-in":       "Basic Duplicators",
  21.    "desc":          "Standard Duplicator styles.",
  22.    "date":          "31 oct 98",
  23.    "author":        "Armin Rigo",
  24.    "author e-mail": "arigo@planetquake.com",
  25.    "quark":         "Version 5.1" }
  26.  
  27.  
  28. from quarkpy.maputils import *
  29. import quarkpy.mapduplicator
  30. import quarkpy.maphandles
  31. import quarkpy.mapcommands
  32. StandardDuplicator = quarkpy.mapduplicator.StandardDuplicator
  33.  
  34.  
  35.  
  36. class BasicDuplicator(StandardDuplicator):
  37.     "Classic basic duplicators (count, offset, angle)."
  38.  
  39.     def readvalues(self):
  40.         StandardDuplicator.readvalues(self)
  41.         s = self.dup["angle"]
  42.         if s:
  43.             self.matrix = matrix_rot_z(float(s)*deg2rad)
  44.  
  45.    # def applylinear(self, matrix, direct=0):
  46.    #     StandardDuplicator.applylinear(self, matrix, direct)
  47.    #     s = self.dup["angle"]
  48.    #     if s:
  49.    #         angle = float(s)*deg2rad
  50.    #         v = quarkx.vect(math.cos(angle), math.sin(angle), 0)
  51.    #         v = matrix * v
  52.    #         if v.x or v.y:
  53.    #             angle = math.atan2(v.y, v.x)*rad2deg
  54.    #             self.dup["angle"] = str(int(angle))
  55.  
  56.  
  57. class LinearDuplicator(StandardDuplicator):
  58.     "Linear (matrix) duplicators (count, offset, linear)."
  59.  
  60.     def readvalues(self):
  61.         StandardDuplicator.readvalues(self)
  62.         #
  63.         # old matrix for backward compatibility
  64.         #
  65.         s = self.dup["linear"]
  66.         if s:
  67.             self.matrix = quarkx.matrix(s)
  68.  
  69.     def applylinear(self, matrix, direct=0):
  70.         s = self.dup["linear"]
  71.         if direct and s:
  72.             m1 = quarkx.matrix(s)
  73.             self.dup["linear"] = str(matrix * m1)
  74.         else:
  75.             StandardDuplicator.applylinear(self, matrix, direct)
  76.             if s:
  77.                 m1 = quarkx.matrix(s)
  78.                 m1 = matrix * m1 * (~matrix)
  79.                 self.dup["linear"] = str(m1)
  80.  
  81.  
  82. class SymXDuplicator(StandardDuplicator):
  83.     "X-Axis Symmetry."
  84.  
  85.     def readvalues(self):
  86.         StandardDuplicator.readvalues(self)
  87.         self.matrix = quarkx.matrix((-1,0,0),(0,1,0),(0,0,1))
  88.  
  89.  
  90. class SymYDuplicator(StandardDuplicator):
  91.     "Y-Axis Symmetry."
  92.  
  93.     def readvalues(self):
  94.         StandardDuplicator.readvalues(self)
  95.         self.matrix = quarkx.matrix((1,0,0),(0,-1,0),(0,0,1))
  96.  
  97.  
  98. class SymZDuplicator(StandardDuplicator):
  99.     "Z-Axis Symmetry."
  100.  
  101.     def readvalues(self):
  102.         StandardDuplicator.readvalues(self)
  103.         self.matrix = quarkx.matrix((1,0,0),(0,1,0),(0,0,-1))
  104.  
  105.  
  106. class SymXYDuplicator(StandardDuplicator):
  107.     "X- and Y-Axis Symmetry (makes 3 images)."
  108.  
  109.     def readvalues(self):
  110.         StandardDuplicator.readvalues(self)
  111.         self.mx = quarkx.matrix((-1,0,0),(0,1,0),(0,0,1))
  112.         self.my = quarkx.matrix((1,0,0),(0,-1,0),(0,0,1))
  113.         self.mxy = quarkx.matrix((-1,0,0),(0,-1,0),(0,0,1))
  114.  
  115.     def do(self, item):
  116.         item2 = item.copy()
  117.         item3 = item.copy()
  118.         item.linear(self.origin, self.mx)
  119.         item2.linear(self.origin, self.my)
  120.         item3.linear(self.origin, self.mxy)
  121.         return [item, item2, item3]
  122.  
  123. class SymXYZDuplicator(StandardDuplicator):
  124.     "XYZ-Axis Symmetry."
  125.  
  126.     def readvalues(self):
  127.         StandardDuplicator.readvalues(self)
  128.         x = 1
  129.         y = 1
  130.         z = 1
  131.         if self.dup["x"]:
  132.             x = -1
  133.         if self.dup["y"]:
  134.             y = -1
  135.         if self.dup["z"]:
  136.             z = -1
  137.         self.matrix = quarkx.matrix((x,0,0),(0,y,0),(0,0,z))
  138.  
  139.  
  140. class DiggingDuplicator(StandardDuplicator):
  141.     "For what is a Digger rather than a Duplicator. (abstract)"
  142.  
  143.     Icon = (ico_dict['ico_mapdups'], 1)
  144.  
  145.     def readvalues(self):
  146.         pass
  147.  
  148.     def makeneg(self, item):
  149.         if not (item.type in (':e', ':b')):
  150.             if self.dup["global"]:
  151.                 item["neg"]="g"
  152.             else:
  153.                 item["neg"]="1"
  154.  
  155.  
  156.  
  157. class Digger(DiggingDuplicator):
  158.     "Makes everything in the group negative."
  159.  
  160.     def do(self, item):
  161.         self.makeneg(item)
  162.         return [item]
  163.  
  164.  
  165.  
  166. class DepthDuplicator(DiggingDuplicator):
  167.     "Digger with a 'depth' parameter. (abstract)"
  168.  
  169.     def readvalues(self):
  170.         self.depth = float(self.dup["depth"])
  171.         if self.depth<=0:
  172.             raise "depth<=0"
  173.  
  174.     def applylinear(self, matrix, direct=0):
  175.         depth = float(self.dup["depth"])
  176.         factor = math.exp(math.log(abs(matrix))/3)
  177.         self.dup["depth"] = quarkx.ftos(depth*factor)
  178.  
  179.  
  180. class HollowMaker(DepthDuplicator):
  181.     "Makes the polyhedrons in the group hollow."
  182.  
  183.     def do(self, item):
  184.         item2 = item.copy()
  185.         item2.inflate(-self.depth)
  186.         self.makeneg(item2)
  187.         return [item, item2]
  188.  
  189.  
  190.  
  191. #
  192. # a buildimages method for this is supplied in
  193. #  mapmiteredges.py, for mitered edges.
  194. #
  195. class WallMaker(DepthDuplicator):
  196.     "Extrude the polyhedrons in the group."
  197.  
  198.     def do(self, item):
  199.         item2 = item.copy()
  200.         item.inflate(self.depth)
  201.         self.makeneg(item2)
  202.         return [item, item2]
  203.  
  204.  
  205. #
  206. # This plug-in introduces a new menu item for Duplicators : "Dissociate Duplicator images".
  207. #
  208.  
  209. def dissociate1click(m):
  210.     editor = mapeditor()
  211.     if editor is None: return
  212.     getmgr = quarkpy.mapduplicator.DupManager
  213.     undo = quarkx.action()
  214.     list = editor.layout.explorer.sellist
  215.     list2=[]
  216.     for obj in list:
  217.         if obj.type == ':d':
  218.            list2.append(obj)
  219.            if obj["out"] and obj.parent is not None:
  220.                for item in obj.parent.subitems:
  221.                    if item!=obj and item.type==':d' and item["out"]:
  222.                        list2.append(item)
  223.  
  224.     for obj in list2:
  225.         if obj.type == ':d':
  226.             mgr = getmgr(obj)
  227.             image = 0
  228.             insertbefore = obj.nextingroup()
  229.             while 1:
  230.                 objlist = mgr.buildimages(image)
  231.                 if len(objlist)==0:
  232.                     break
  233.                 image = image + 1
  234.                 new = quarkx.newobj("%s (%d):g" % (obj.shortname, image))
  235.                 for o in objlist:
  236.                     new.appenditem(o)
  237.                 undo.put(obj.parent, new, insertbefore)
  238.             undo.exchange(obj, None)    # removes the duplicator
  239.     editor.ok(undo, "dissociate images")
  240.  
  241.  
  242. dissociate = quarkpy.qmenu.item("Dissociate Duplicator images", dissociate1click,"|Dissociate Duplicator images:\n\nOnly active when you have selected a duplicator. This will create actural copies of the duplicator-object(s), and remove the duplicator itself.\n\nIf the duplicator is an 'out' duplicator, and there are others (immediately) in the group, they will all be dissociated together.|intro.mapeditor.menu.html#disdupimages")
  243.  
  244.  
  245. #
  246. # Add item to the Commands menu.
  247. #
  248.  
  249. import quarkpy.qmenu
  250. import quarkpy.mapcommands
  251. import quarkpy.mapentities
  252.  
  253.  
  254. def commands1click(menu, oldclick = quarkpy.mapcommands.onclick):
  255.     oldclick(menu)
  256.     editor = mapeditor()
  257.     if editor is None: return
  258.     if ":d" in map(lambda obj: obj.type, editor.layout.explorer.sellist):   # any Duplicator selected ?
  259.         dissociate.state = 0
  260.     else:
  261.         dissociate.state = qmenu.disabled
  262.  
  263. quarkpy.mapcommands.items.append(quarkpy.qmenu.sep)   # separator
  264. quarkpy.mapcommands.items.append(dissociate)
  265. quarkpy.mapcommands.onclick = commands1click
  266.  
  267.  
  268. #
  269. # Add item to the Duplicators pop-up menu.
  270. #
  271.  
  272. def DuplicatorMenu(o, editor, oldmenu = quarkpy.mapentities.DuplicatorType.menubegin.im_func):
  273.     dissociate.state = 0
  274.     return oldmenu(o, editor) + [dissociate, quarkpy.qmenu.sep]
  275.  
  276. quarkpy.mapentities.DuplicatorType.menubegin = DuplicatorMenu
  277.  
  278.  
  279. #
  280. # Register the duplicator types from this plug-in.
  281. #
  282.  
  283. quarkpy.mapduplicator.DupCodes.update({
  284.   "dup basic":       BasicDuplicator,
  285.   "dup lin":         LinearDuplicator,
  286.   "dup symx":        SymXDuplicator,
  287.   "dup symy":        SymYDuplicator,
  288.   "dup symz":        SymZDuplicator,
  289.   "dup symxy":       SymXYDuplicator,
  290.   "dup symxyz":      SymXYZDuplicator,
  291.   "digger":          Digger,
  292.   "hollow maker":    HollowMaker,
  293.   "wall maker":      WallMaker,
  294. })
  295.  
  296. #
  297. # Clear texture cycle files cache (so that edits will
  298. #   be reloaded)
  299. #
  300.  
  301. def resetTextureCycleClick(m):
  302.     quarkpy.mapduplicator.Dup_Tex_Dicts={}
  303.  
  304. quarkpy.mapcommands.items.append(qmenu.item("Reset Texture Cycle",resetTextureCycleClick,"|Reset Texture Cycle:\n\nReload files specifying texture cycles for duplicators.|intro.mapeditor.menu.html#disdupimages"))
  305.  
  306. # ----------- REVISION HISTORY ------------
  307. #
  308. #
  309. # $Log: mapdups.py,v $
  310. # Revision 1.12  2003/03/24 08:57:15  cdunde
  311. # To update info and link to infobase
  312. #
  313. # Revision 1.11  2001/10/22 10:15:48  tiglari
  314. # live pointer hunt, revise icon loading
  315. #
  316. # Revision 1.10  2001/09/23 07:00:34  tiglari
  317. # mitered edges for wall maker duplicator
  318. #
  319. # Revision 1.9  2001/08/15 17:49:55  decker_dk
  320. # Added a 'dup symxyz' with toggleable axes.
  321. #
  322. # Revision 1.8  2001/08/07 23:33:43  tiglari
  323. # reset texture cycle command
  324. #
  325. # Revision 1.7  2001/05/19 03:55:42  tiglari
  326. # dissociate one, dissociate all, for 'out' duplicators
  327. #
  328. # Revision 1.6  2001/05/12 10:15:56  tiglari
  329. # remove matrix2 (buildLinearMatrix) support from linear duplicator
  330. #
  331. # Revision 1.5  2001/04/08 02:44:15  tiglari
  332. # fix conflict
  333. #
  334. # Revision 1.4  2001/04/06 06:00:35  tiglari
  335. # fixed a messed up change to Linear Duplicator readavalues
  336. #
  337. # Revision 1.3  2001/03/29 09:28:55  tiglari
  338. # scale and rotate specifics for duplicators
  339. #
  340. # Revision 1.2  2000/06/03 10:25:30  alexander
  341. # added cvs headers
  342. #
  343. #
  344. #
  345. #
  346.